﻿
#region Using directives

using System;
using System.Collections;
using System.Collections.Specialized;


using System.Web.Configuration;
using System.Data;
using System.Data.Common;
using System.Configuration.Provider;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using InfoExpress.ESM.Domains;
using InfoExpress.ESM.DataAccess;
using InfoExpress.ESM.DataAccess.Bases;

#endregion

namespace InfoExpress.ESM.DataAccess.SqlClient
{
	/// <summary>
	/// This class is the Sql implementation of the NetTiersProvider.
	/// </summary>
	public sealed class SqlNetTiersProvider : InfoExpress.ESM.DataAccess.Bases.NetTiersProvider
	{
		private static object syncRoot = new Object();
		private string _applicationName;
        private string _connectionString;
        private bool _useStoredProcedure;
        string _providerInvariantName;
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SqlNetTiersProvider"/> class.
		///</summary>
		public SqlNetTiersProvider()
		{	
		}		
		
		/// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
		public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "SqlNetTiersProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "NetTiers Sql provider");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            // Initialize _applicationName
            _applicationName = config["applicationName"];

            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = "/";
            }
            config.Remove("applicationName");


            #region "Initialize UseStoredProcedure"
            string storedProcedure  = config["useStoredProcedure"];
           	if (string.IsNullOrEmpty(storedProcedure))
            {
                throw new ProviderException("Empty or missing useStoredProcedure");
            }
            this._useStoredProcedure = Convert.ToBoolean(config["useStoredProcedure"]);
            config.Remove("useStoredProcedure");
            #endregion

			#region ConnectionString

			// Initialize _connectionString
			_connectionString = config["connectionString"];
			config.Remove("connectionString");

			string connect = config["connectionStringName"];
			config.Remove("connectionStringName");

			if ( String.IsNullOrEmpty(_connectionString) )
			{
				if ( String.IsNullOrEmpty(connect) )
				{
					throw new ProviderException("Empty or missing connectionStringName");
				}

				if ( DataRepository.ConnectionStrings[connect] == null )
				{
					throw new ProviderException("Missing connection string");
				}

				_connectionString = DataRepository.ConnectionStrings[connect].ConnectionString;
			}

            if ( String.IsNullOrEmpty(_connectionString) )
            {
                throw new ProviderException("Empty connection string");
			}

			#endregion
            
             #region "_providerInvariantName"

            // initialize _providerInvariantName
            this._providerInvariantName = config["providerInvariantName"];

            if (String.IsNullOrEmpty(_providerInvariantName))
            {
                throw new ProviderException("Empty or missing providerInvariantName");
            }
            config.Remove("providerInvariantName");

            #endregion

        }
		
		/// <summary>
		/// Creates a new <c cref="TransactionManager"/> instance from the current datasource.
		/// </summary>
		/// <returns></returns>
		public override TransactionManager CreateTransaction()
		{
			return new TransactionManager(this._connectionString);
		}
		
		/// <summary>
		/// Gets a value indicating whether to use stored procedure or not.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this repository use stored procedures; otherwise, <c>false</c>.
		/// </value>
		public bool UseStoredProcedure
		{
			get {return this._useStoredProcedure;}
			set {this._useStoredProcedure = value;}
		}
		
		 /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        /// <value>The connection string.</value>
		public string ConnectionString
		{
			get {return this._connectionString;}
			set {this._connectionString = value;}
		}
		
		/// <summary>
	    /// Gets or sets the invariant provider name listed in the DbProviderFactories machine.config section.
	    /// </summary>
	    /// <value>The name of the provider invariant.</value>
	    public string ProviderInvariantName
	    {
	        get { return this._providerInvariantName; }
	        set { this._providerInvariantName = value; }
	    }		
		
		///<summary>
		/// Indicates if the current <c cref="NetTiersProvider"/> implementation supports Transacton.
		///</summary>
		public override bool IsTransactionSupported
		{
			get
			{
				return true;
			}
		}

		
		#region "EnumsProvider"
			
		private SqlEnumsProvider innerSqlEnumsProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Enums"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override EnumsProviderBase EnumsProvider
		{
			get
			{
				if (innerSqlEnumsProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlEnumsProvider == null)
						{
							this.innerSqlEnumsProvider = new SqlEnumsProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlEnumsProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlEnumsProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlEnumsProvider SqlEnumsProvider
		{
			get {return EnumsProvider as SqlEnumsProvider;}
		}
		
		#endregion
		
		
		#region "TeacherProvider"
			
		private SqlTeacherProvider innerSqlTeacherProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Teacher"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override TeacherProviderBase TeacherProvider
		{
			get
			{
				if (innerSqlTeacherProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlTeacherProvider == null)
						{
							this.innerSqlTeacherProvider = new SqlTeacherProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlTeacherProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlTeacherProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlTeacherProvider SqlTeacherProvider
		{
			get {return TeacherProvider as SqlTeacherProvider;}
		}
		
		#endregion
		
		
		#region "ProgramShiftProvider"
			
		private SqlProgramShiftProvider innerSqlProgramShiftProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ProgramShift"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProgramShiftProviderBase ProgramShiftProvider
		{
			get
			{
				if (innerSqlProgramShiftProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProgramShiftProvider == null)
						{
							this.innerSqlProgramShiftProvider = new SqlProgramShiftProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProgramShiftProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlProgramShiftProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProgramShiftProvider SqlProgramShiftProvider
		{
			get {return ProgramShiftProvider as SqlProgramShiftProvider;}
		}
		
		#endregion
		
		
		#region "SessionProvider"
			
		private SqlSessionProvider innerSqlSessionProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Session"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SessionProviderBase SessionProvider
		{
			get
			{
				if (innerSqlSessionProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSessionProvider == null)
						{
							this.innerSqlSessionProvider = new SqlSessionProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSessionProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlSessionProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSessionProvider SqlSessionProvider
		{
			get {return SessionProvider as SqlSessionProvider;}
		}
		
		#endregion
		
		
		#region "PeriodProvider"
			
		private SqlPeriodProvider innerSqlPeriodProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Period"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PeriodProviderBase PeriodProvider
		{
			get
			{
				if (innerSqlPeriodProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPeriodProvider == null)
						{
							this.innerSqlPeriodProvider = new SqlPeriodProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPeriodProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPeriodProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPeriodProvider SqlPeriodProvider
		{
			get {return PeriodProvider as SqlPeriodProvider;}
		}
		
		#endregion
		
		
		#region "SessionPeriodProvider"
			
		private SqlSessionPeriodProvider innerSqlSessionPeriodProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SessionPeriod"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SessionPeriodProviderBase SessionPeriodProvider
		{
			get
			{
				if (innerSqlSessionPeriodProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSessionPeriodProvider == null)
						{
							this.innerSqlSessionPeriodProvider = new SqlSessionPeriodProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSessionPeriodProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlSessionPeriodProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSessionPeriodProvider SqlSessionPeriodProvider
		{
			get {return SessionPeriodProvider as SqlSessionPeriodProvider;}
		}
		
		#endregion
		
		
		#region "CategoryProvider"
			
		private SqlCategoryProvider innerSqlCategoryProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Category"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override CategoryProviderBase CategoryProvider
		{
			get
			{
				if (innerSqlCategoryProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlCategoryProvider == null)
						{
							this.innerSqlCategoryProvider = new SqlCategoryProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlCategoryProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlCategoryProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlCategoryProvider SqlCategoryProvider
		{
			get {return CategoryProvider as SqlCategoryProvider;}
		}
		
		#endregion
		
		
		#region "ShiftProvider"
			
		private SqlShiftProvider innerSqlShiftProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Shift"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ShiftProviderBase ShiftProvider
		{
			get
			{
				if (innerSqlShiftProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlShiftProvider == null)
						{
							this.innerSqlShiftProvider = new SqlShiftProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlShiftProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlShiftProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlShiftProvider SqlShiftProvider
		{
			get {return ShiftProvider as SqlShiftProvider;}
		}
		
		#endregion
		
		
		#region "AccountProvider"
			
		private SqlAccountProvider innerSqlAccountProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Account"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override AccountProviderBase AccountProvider
		{
			get
			{
				if (innerSqlAccountProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlAccountProvider == null)
						{
							this.innerSqlAccountProvider = new SqlAccountProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlAccountProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlAccountProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlAccountProvider SqlAccountProvider
		{
			get {return AccountProvider as SqlAccountProvider;}
		}
		
		#endregion
		
		
		#region "ProgramProvider"
			
		private SqlProgramProvider innerSqlProgramProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Program"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProgramProviderBase ProgramProvider
		{
			get
			{
				if (innerSqlProgramProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProgramProvider == null)
						{
							this.innerSqlProgramProvider = new SqlProgramProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProgramProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlProgramProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProgramProvider SqlProgramProvider
		{
			get {return ProgramProvider as SqlProgramProvider;}
		}
		
		#endregion
		
		
		#region "StudentProvider"
			
		private SqlStudentProvider innerSqlStudentProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Student"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override StudentProviderBase StudentProvider
		{
			get
			{
				if (innerSqlStudentProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlStudentProvider == null)
						{
							this.innerSqlStudentProvider = new SqlStudentProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlStudentProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlStudentProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlStudentProvider SqlStudentProvider
		{
			get {return StudentProvider as SqlStudentProvider;}
		}
		
		#endregion
		
		
		#region "SafeNameClassProvider"
			
		private SqlSafeNameClassProvider innerSqlSafeNameClassProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SafeNameClass"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SafeNameClassProviderBase SafeNameClassProvider
		{
			get
			{
				if (innerSqlSafeNameClassProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSafeNameClassProvider == null)
						{
							this.innerSqlSafeNameClassProvider = new SqlSafeNameClassProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSafeNameClassProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlSafeNameClassProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSafeNameClassProvider SqlSafeNameClassProvider
		{
			get {return SafeNameClassProvider as SqlSafeNameClassProvider;}
		}
		
		#endregion
		
		
		#region "ClassScheduleProvider"
			
		private SqlClassScheduleProvider innerSqlClassScheduleProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ClassSchedule"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ClassScheduleProviderBase ClassScheduleProvider
		{
			get
			{
				if (innerSqlClassScheduleProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlClassScheduleProvider == null)
						{
							this.innerSqlClassScheduleProvider = new SqlClassScheduleProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlClassScheduleProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlClassScheduleProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlClassScheduleProvider SqlClassScheduleProvider
		{
			get {return ClassScheduleProvider as SqlClassScheduleProvider;}
		}
		
		#endregion
		
		
		#region "ClassTeacherScheduleProvider"
			
		private SqlClassTeacherScheduleProvider innerSqlClassTeacherScheduleProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ClassTeacherSchedule"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ClassTeacherScheduleProviderBase ClassTeacherScheduleProvider
		{
			get
			{
				if (innerSqlClassTeacherScheduleProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlClassTeacherScheduleProvider == null)
						{
							this.innerSqlClassTeacherScheduleProvider = new SqlClassTeacherScheduleProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlClassTeacherScheduleProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlClassTeacherScheduleProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlClassTeacherScheduleProvider SqlClassTeacherScheduleProvider
		{
			get {return ClassTeacherScheduleProvider as SqlClassTeacherScheduleProvider;}
		}
		
		#endregion
		
		
		#region "PeriodShiftProvider"
			
		private SqlPeriodShiftProvider innerSqlPeriodShiftProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="PeriodShift"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PeriodShiftProviderBase PeriodShiftProvider
		{
			get
			{
				if (innerSqlPeriodShiftProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPeriodShiftProvider == null)
						{
							this.innerSqlPeriodShiftProvider = new SqlPeriodShiftProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPeriodShiftProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPeriodShiftProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPeriodShiftProvider SqlPeriodShiftProvider
		{
			get {return PeriodShiftProvider as SqlPeriodShiftProvider;}
		}
		
		#endregion
		
		
		#region "DetailMissPeriodProvider"
			
		private SqlDetailMissPeriodProvider innerSqlDetailMissPeriodProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="DetailMissPeriod"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override DetailMissPeriodProviderBase DetailMissPeriodProvider
		{
			get
			{
				if (innerSqlDetailMissPeriodProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlDetailMissPeriodProvider == null)
						{
							this.innerSqlDetailMissPeriodProvider = new SqlDetailMissPeriodProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlDetailMissPeriodProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlDetailMissPeriodProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlDetailMissPeriodProvider SqlDetailMissPeriodProvider
		{
			get {return DetailMissPeriodProvider as SqlDetailMissPeriodProvider;}
		}
		
		#endregion
		
		
		#region "DetailPeriodProvider"
			
		private SqlDetailPeriodProvider innerSqlDetailPeriodProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="DetailPeriod"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override DetailPeriodProviderBase DetailPeriodProvider
		{
			get
			{
				if (innerSqlDetailPeriodProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlDetailPeriodProvider == null)
						{
							this.innerSqlDetailPeriodProvider = new SqlDetailPeriodProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlDetailPeriodProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlDetailPeriodProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlDetailPeriodProvider SqlDetailPeriodProvider
		{
			get {return DetailPeriodProvider as SqlDetailPeriodProvider;}
		}
		
		#endregion
		
		
		#region "FreePeriodProvider"
			
		private SqlFreePeriodProvider innerSqlFreePeriodProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="FreePeriod"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override FreePeriodProviderBase FreePeriodProvider
		{
			get
			{
				if (innerSqlFreePeriodProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlFreePeriodProvider == null)
						{
							this.innerSqlFreePeriodProvider = new SqlFreePeriodProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlFreePeriodProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlFreePeriodProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlFreePeriodProvider SqlFreePeriodProvider
		{
			get {return FreePeriodProvider as SqlFreePeriodProvider;}
		}
		
		#endregion
		
		
		
		#region "General data access methods"

		#region "ExecuteNonQuery"
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper);	
			
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(commandType, commandText);	
		}
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteNonQuery(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataReader"
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(commandWrapper);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteReader(commandType, commandText);	
		}
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteReader(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataSet"
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(commandWrapper);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteDataSet(commandType, commandText);	
		}
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteDataSet(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteScalar"
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(commandWrapper);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(commandWrapper, transactionManager.TransactionObject);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteScalar(commandType, commandText);	
		}
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteScalar(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#endregion


	}
}
